#include "setgpa.h"
#include "ui_setgpa.h"
#include<QSqlQuery>

SetGPA::SetGPA(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::SetGPA)
{
    ui->setupUi(this);


}

SetGPA::~SetGPA()
{
    delete ui;
}



//修改成绩成功按钮
void SetGPA::on_pushButton_clicked()
{

    int cpp,shudian,lisan,gaoshu,xiandai,dawu;
    QString id_name=ui->comboBox->currentText(),id="";
    //从id_name中提取id
    for(QChar s:id_name){
        if(s!=' ')id+=s;
        else break;
    }

    //成绩值与微调框值绑定
    cpp=ui->spinBox1->value();
    shudian=ui->spinBox_4->value();
    lisan=ui->spinBox_5->value();
    gaoshu=ui->spinBox_6->value();
    xiandai=ui->spinBox_7->value();
    dawu=ui->spinBox_8->value();


    QSqlQuery query;
    //修改成绩
    query.prepare("update gpa set cpp=:cpp,shudian=:shudian,\
    lisan=:lisan,gaoshu=:gaoshu,xiandai=:xiandai,dawu=:dawu where id=:id");
    query.bindValue(":id",id);
    query.bindValue(":cpp",cpp);
    query.bindValue(":shudian",shudian);
    query.bindValue(":lisan",lisan);
    query.bindValue(":gaoshu",gaoshu);
    query.bindValue(":xiandai",xiandai);
    query.bindValue(":dawu",dawu);
    if(query.exec()){
        ui->tip->setText("成绩修改成功！");
    }
    else ui->tip->setText("修改失败！");
}

//返回成绩管理界面
void SetGPA::on_pushButton_2_clicked()
{
    this->close();
}

//连接成绩滑动框和微调框的信号与槽
void SetGPA::on_spinBox1_valueChanged(int arg1)
{
    ui->horizontalSlider1->setValue(arg1);
}

void SetGPA::on_horizontalSlider1_valueChanged(int value)
{
    ui->spinBox1->setValue(value);
}

void SetGPA::on_spinBox_4_valueChanged(int arg1)
{
    ui->horizontalSlider_4->setValue(arg1);
}

void SetGPA::on_horizontalSlider_4_valueChanged(int value)
{
    ui->spinBox_4->setValue(value);
}

void SetGPA::on_spinBox_5_valueChanged(int arg1)
{
    ui->horizontalSlider_5->setValue(arg1);
}

void SetGPA::on_horizontalSlider_5_valueChanged(int value)
{
    ui->spinBox_5->setValue(value);
}

void SetGPA::on_spinBox_6_valueChanged(int arg1)
{
    ui->horizontalSlider_6->setValue(arg1);
}

void SetGPA::on_horizontalSlider_6_valueChanged(int value)
{
    ui->spinBox_6->setValue(value);
}

void SetGPA::on_spinBox_7_valueChanged(int arg1)
{
    ui->horizontalSlider_7->setValue(arg1);
}

void SetGPA::on_horizontalSlider_7_valueChanged(int value)
{
    ui->spinBox_7->setValue(value);
}

void SetGPA::on_spinBox_8_valueChanged(int arg1)
{
    ui->horizontalSlider_8->setValue(arg1);
}

void SetGPA::on_horizontalSlider_8_valueChanged(int value)
{
    ui->spinBox_8->setValue(value);
}
